Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Basic motivation here is to "flatten" out RBAC permissions in order to make them more generic, action-based, and human readable. The assumption of different "levels" (ie. ReadWrite -> Write -> Read) is instead replaced with generic tokens that can be enumerated in an array, allowing different actions to be easily added and scanned within
roles.json
. For example:This allows complex route-based actions like "rescheduling" to be represented as specific, named permissions in roles so that it's easy to see which users can do what. Note also here that
create
,update
, anddelete
are also arbitrary and represent the maximum possible granularity. For endpoints that aren't as sensitive this could simply beedit
, or evenany
- the meaning of the tokens is left up to the implementer and where/how they use them in the routes middleware.Additionally for brevity the token
all
is introduced as a shortcut to allow all permissions:Middleware Shortcuts
The middleware also now allows shortcuts that make adding permission checks simpler:
The middleware functionality itself is the same, ie. it can be applied to each route or cascade with
.use
.Multi-Tenancy
As multi-tenancy is often layered in after a project has gained maturity, a few tweaks were made to assume
global
scope out of the box. However this is also now more easily tweaked later:Note that the grunt work of adding
organization
fields to each model, filtering searches by org etc remain the same. Streamlining that (if necessary) is left as out of scope for this PR.Also note:
I need some input on the motivation behind
permissions.json
as that will need to be updated to fit in here.